
DIRS=
#DIRS += lib
DIRS += package

ROOTDIR  = $(shell pwd)
BUILDLDIR = $(ROOTDIR)/build
#LDFLAGS = -L$(BUILDLDIR)/lib -I$(BUILDLDIR)/include 

export ROOTDIR BUILDLDIR 
export CC=gcc
export CXX=g++


.PHONY: all
all:package_only package_install
#lib_only lib_install
.PHONY: install
install:
	for dir in $(DIRS); do [ ! -d $$dir ] || make -C $$dir install ; done	

.PHONY: clean
clean:
	for dir in $(DIRS); do [ ! -d $$dir ] || make -C $$dir clean ; done	

.PHONY: distclean
distclean:
	for dir in $(DIRS); do [ ! -d $$dir ] || make -C $$dir clean ; done	
	rm -rf $(BUILDLDIR)/


%_only:
	@case "$(@)" in \
	*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
	     t=`expr $(@) : '[^/]*/\(.*\)'`; \
	     make -C $$d $$t;; \
	*)   make -C $(@:_only=);; \
	esac

%_install:
	@case "$(@)" in \
	*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
	     t=`expr $(@) : '[^/]*/\(.*\)'`; \
	     make -C $$d $$t;; \
	*)   make -C $(@:_install=) install;; \
	esac

%_clean:
	@case "$(@)" in \
	*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
	     t=`expr $(@) : '[^/]*/\(.*\)'`; \
	     make -C $$d $$t;; \
	*)   make -C $(@:_clean=) clean;; \
	esac
